<template>
	<!-- 详细情况 -->
	<view>
		<!-- 轮播图 -->
		<u-swiper height="225" width="100%" radius="0" :list="banner || df" circular></u-swiper>
		<view class="c-m-tard-1">
			<view class="m-card u-m-30 ">
				<view class="u-flex u-flex-y-center">
					<text class="u-m-l-10 u-font-32 m-font-b">{{ details.properties_name }}</text>
					<text class="u-m-l-30 u-font-32 m-font-b">{{ details.bedroom }}室{{ details.room }}厅</text>
				</view>

				<xiangxi :list="jiangli" :col="2" :type="type"></xiangxi>

				<!-- <view class="u-flex u-flex-items-center u-m-t-40">
					<u-icon name="huore" customPrefix="master" size="22" color="#ccc"></u-icon>
					<text class="m-c-9 u-m-l-10">房源热度</text>
				</view>

				<view class="u-p-t-25">
					<u-grid :col="4">
						<u-grid-item v-for="(items, ixd) in recom" :key="ixd" @click="nextNav(item.url)">
							<text class="bepad">{{ items.shu }}</text>
							<view class="m-c-b u-m-t-20 u-font-23">{{ items.name }}</view>
						</u-grid-item>
					</u-grid>
				</view> -->
			</view>

			<view class="m-card u-m-30">
				<view class="u-flex u-flex-y-center">
					<u-image width="4" height="22" :src="oss + '/mine/shu.png'"></u-image>
					<text class="u-m-l-10 u-font-40 m-font-b">更多操作</text>
				</view>
				<view class="u-p-t-60">
					<u-grid :col="4">
						<u-grid-item v-for="(item, index) in record" :key="index" @click="getswitch(item.type)">
							<view class="u-m-t-20 u-m-b-30 ">
								<view class="u-flex u-flex-center">
									<u-icon :name="item.icon" :size="22"></u-icon>
								</view>
								<view class="c5a u-m-t-20">{{ item.name }}</view>
								<view v-if="index > 6" class="u-m-t-60">
									<u-icon name="more-dot-fill" :size="30"></u-icon>
								</view>
							</view>
						</u-grid-item>
					</u-grid>
				</view>
			</view>
			<u-popup :show="show" @close="show = false" mode="top" :safeAreaInsetTop="true">
				<view class="u-m-t-30 m-mg-lr u-p-b-30">
					<view class="u-flex u-flex-center u-flex-items-center">
						<view class="u-font-34 m-font-b">修改房子价格</view>
					</view>
					<view class="">旧价格：</view>
					<view class="u-m-t-30 u-m-b-30 boxborder">
						<u--input border="surround" v-model="details.price" :disabled="true"></u--input>
					</view>
					<view class="">新价格：</view>
					<view class="u-m-t-30 u-m-b-30 boxborder">
						<u--input border="surround" :placeholder="type==1?'请输入新的价格(单位万)':'请输入新的价格(单位元)'" v-model="price"></u--input>
					</view>
					<view class="boxque" @click="getque">确定</view>
				</view>
			</u-popup>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: '',
				banner: [],
				recom: [{
						shu: 0,
						name: '浏览量',
						url: ''
					},
					{
						shu: 0,
						name: '关注量',
						url: ''
					},
					{
						shu: 0,
						name: '查看量',
						url: ''
					},
					{
						shu: 0,
						name: '咨询量',
						url: ''
					}
				],
				jiangli: [{
						shu: 0,
						name: ''
					},
					{
						shu: 0,
						name: ''
					}
				],
				jiangjia: null,
				record: [{
						icon: 'https://neidangjia.oss-accelerate.aliyuncs.com/mine/jr.png',
						name: '聊天记录',
						type: 1
					},
					{
						icon: 'https://neidangjia.oss-accelerate.aliyuncs.com/mine/ja.png',
						name: '调整价格',
						type: 2
					},
					{
						icon: 'https://neidangjia.oss-accelerate.aliyuncs.com/mine/jv.png',
						name: '修改信息',
						type: 3
					},
					{
						icon: 'https://neidangjia.oss-accelerate.aliyuncs.com/mine/jm.png',
						name: '停止出租',
						type: 4
					},
					{
						icon: 'https://neidangjia.oss-accelerate.aliyuncs.com/mine/jw.png',
						name: '联系管家',
						type: 5
					},
					{
						icon: 'https://neidangjia.oss-accelerate.aliyuncs.com/mine/ju.png',
						name: '证件协议',
						type: 6
					},
					{
						icon: 'https://neidangjia.oss-accelerate.aliyuncs.com/mine/jk.png',
						name: '房屋图片',
						type: 7
					},
					{
						icons: 'https://neidangjia.oss-accelerate.aliyuncs.com/mine/dian.png',
						type: 8
					}
				],
				details: {},
				type: null,
				id: null,
				show: false,
				price: null,
				fromData: {}
			};
		},
		async onLoad(e) {
			if (e.type) {
				this.type = +e.type;
			}
			if (e.id) {
				this.id = +e.id;
				this.getDetails(+e.id);

				if (this.type != 1) {
					let res = await this.require('getAouse', {
						id: +e.id
					});
					if (res) {
						this.fromData = res;
					}
				}
			}
		},
		async onShow() {
			await this.getDetails(this.id);
		},
		methods: {
			async getque() {
				let p = /^\d+$/.test(this.price);
				if (!p) {
					this.$u.toast('请输入纯数字');
					return;
				} else {
					if (this.type == 1) {
						let res = await this.require('reviseprice', {
							id: this.details.id,
							price: this.price * 10000
						});
						if (res) {
							this.show = false;
							uni.$u.toast('修改成功');
							this.getDetails(this.id);
						}
					} else {
						this.fromData.price = this.price
						let res = await this.require('revisehouse',this.fromData);
						if (res) {
							this.show = false;
							uni.$u.toast('修改成功');
							this.getDetails(this.id);
						}
					}

				}
			},
			async getDetails(id) {
				let getJie = this.type != 1 ? 'getLease' : 'getTow';
				let res = await this.require(getJie, {
					id
				});
				if (res) {
					uni.setNavigationBarTitle({
						title: res.properties_name
					});
					this.details = res;
					this.jiangli[0].shu = res.price;
					this.jiangli[1].name = res.createtime;
					this.banner = this.details.images ? this.details.images.split(',') : [];
					let ty = this.type == 1 ? '停止出售' : '停止出租';
					let tyb = this.type == 1 ? '开始出售' : '开始出租';
					this.record[3].name = res.switch == 1 ? ty : tyb;
					this.details.price = this.get_look_two(+res.price);
					if (this.type == 1) {
						let str = this.details.towhouseprice.result + '';
						if (str.indexOf('-') != -1) {
							let chang = str.indexOf('-');
							str = str.substring(chang + 1, str.length);
							this.jiangli[1].shu = str;
						} else {
							this.jiangli[1].shu = 0;
						}
					}
				}
			},
			async getswitch(ind) {
				let examinedata = this.details.examinedata;
				if (examinedata == 1) {
					switch (ind) {
						case 1: //记录
							this.nextNav('/pages/tabbar/news');
							break;
						case 2: //价格
							this.show = true;
							break;
						case 3: //信息
							if (this.type === 1) {
								this.nextNav('/pages/mine/shangchuan?id=' + this.details.id);
							} else {
								this.nextNav('/pages/zufang/shangchuan?id=' + this.details.id);
							}
							break;
						case 4: //出售状态  gelltab
							let selltab = this.type === 1 ? 'selltab' : 'getSelltab';
							let res = await this.require(selltab, {
								id: this.id,
								switch: this.details.switch == 0 ? 1 : 0
							});
							if (res) {
								if (this.type === 1) {
									uni.$u.toast(`你${this.details.switch == 0 ? '开始' : '停止'} 出售房屋`);
								} else {
									uni.$u.toast(`你${this.details.switch == 0 ? '开始' : '停止'} 出租房屋`);
								}
								this.getDetails(this.id);
							}
							break;
						case 5: //管家
							// this.nextNav('/pages/news/xiaoxi?id=' + this.id); //ID不是真实的
							this.nextNav('no');
							break;
						case 6: //证件协议
							this.nextNav('no');
							break;
						case 7: //房屋图片
							if (this.type === 1) {
								this.nextNav('/pages/mine/tupian?id=' + this.details.id);
							} else {
								this.nextNav('/pages/mine/tupian?id=' + this.details.id + '&type=0');
							}
							break;
						case 8:
							this.nextNav('no');
							break;
						default:
							break;
					}
				} else {
					let value = examinedata == 0 ? '正在审核中' : examinedata == 2 ? '审核未通过' : '';
					uni.$u.toast(value);
				}
			}
		}
	};
</script>

<style lang="scss" scoped>
	.c-m-tard {
		position: absolute;
		margin-top: -70rpx;
		width: 100%;
	}

	.boxque {
		padding: 20rpx 60rpx;
		text-align: center;
		color: #fff;
		background-color: #0e5642;
		border-radius: 5rpx;
	}

	.bepad {
		font-size: 40rpx;
		font-weight: bold;
		color: #2c2a2b;
	}

	.c5a {
		color: #5a5a5a;
	}

	.boxborder {
		border: 2rpx solid #f1f1f1;
	}
</style>
